<!DOCTYPE html>
<html>
    <head>
        <title>Math操作 </title>
		<meta charset="utf-8" />
    </head>
    <body>

    </body>
    <script>
        //Math.round()四舍五入操作
        var result1 = Math.round(1.7);
        console.log(result1);

        var num = 2.16;
        num = num * 10;
        var result2 = Math.round(num);
        result2 = result2/10;

        //Math.floor()向下取整  Math.ceil()向上取整
        var result3 = Math.floor(1.6);
        var result4 = Math.ceil(1.3);
        console.log(result3, result4);

        //Math.random()
        /**
         * Math.random()取值范围0<=result<1的小数
         * 如果变换随机值的范围，可以乘以对应的值
        */
        var result = Math.random();
        //console.log(result);

        var arr = ["hello", "world", "javascript", "math"];
        var index = result*arr.length;
        index = parseInt(index);
        console.log(index);
        console.log(arr[index]);
    </script>
</html>